package com.red.wood.dubbo.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.red.wood.common.util.CommonUtils;
import com.red.wood.dubbo.dao.IrcsBusinessDataDao;
import com.red.wood.dubbo.service.IrcsBusinessDataService;
import com.red.wood.dubbo.util.ProvinceParse;
import com.red.wood.dubbo.util.ReadIPFile;

@Service
public class IrcsBusinessDataServiceImpl implements IrcsBusinessDataService{

	private static final Log log = LogFactory.getLog(IrcsBusinessDataServiceImpl.class);
	
	@Autowired
	private IrcsBusinessDataDao dao;

	@Override
	public List<Map<String, Object>> getIrcsDataInfo() {
		List<Map<String,Object>> list = dao.getIrcsDataInfo();
		if(list != null && list.size() > 0) {
			for(Map<String,Object> map : list) {
				String ircsAdd = CommonUtils.valueOf(map.get("IRCSADD"));
				String province = ProvinceParse.addressAdscription(ircsAdd);
				map.put("PROVINCE",province);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getIrcsHouseInfo(int min, int max) {
		List<Map<String,Object>> list = dao.getIrcsHouseInfo(min,max);
		/*if(list != null && list.size() > 0) {
			for(Map<String,Object> map : list) {
				String houseProvince = CommonUtils.valueOf(map.get("HOUSEPROVINCE"));
				String province = ProvinceParse.addressAdscription(houseProvince);
				map.put("HOUSEPROVINCE",province);
			}
		}*/
		return list;
	}

	@Override
	public List<Map<String, Object>> getIrcsIpInfo(int min, int max) {
		List<Map<String,Object>> list = null;
		try {
			list = dao.getIrcsIpInfo(min, max);
			if(list != null && list.size() > 0) {
				for(Map<String,Object> map : list) {
					String startIp = CommonUtils.valueOf(map.get("STARTIP"));
					String[] area = ReadIPFile.getInstance().find(startIp);
					map.put("PROVINCE",area[1]);
				}
			}
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getIrcsBandWidthInfo(int min, int max) {
		List<Map<String,Object>> list = null;
		try {
			list = dao.getIrcsBandWidthInfo(min, max);
			if(list != null && list.size() > 0) {
				for(Map<String,Object> map : list) {
					String ip = CommonUtils.valueOf(map.get("GATEWAYIP"));
					String[] area = ReadIPFile.getInstance().find(ip);
					map.put("PROVINCE",area[1]);
				}
			}
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getIrcsUserInfo(int min, int max) {
		List<Map<String,Object>> list = dao.getIrcsUserInfo(min, max);
		if(list != null && list.size() > 0) {
			for(Map<String,Object> map : list) {
				String address = CommonUtils.valueOf(map.get("ADDRESS"));
				String province = ProvinceParse.addressAdscription(address);
				map.put("PROVINCE",province);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getIrcsDomainInfo(int min, int max) {
		return dao.getIrcsDomainInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getIrcsPublicDomainInfo(int min, int max) {
		return dao.getIrcsPublicDomainInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getIrcsEmergencyContactInfo(int min, int max) {
		return dao.getIrcsEmergencyContactInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getIrcsHouseOfficerInfo(int min, int max) {
		return dao.getIrcsHouseOfficerInfo(min, max);
	}

	@Override
	public List<Map<String, Object>> getIrcsServiceInfo(int min, int max) {
		return dao.getIrcsServiceInfo(min, max);
	}

}
